How to calculate square root in PHP [explained] [on hold]
Posted
by
Enes Imsirovic
on Programmers
See other posts from Programmers
or by Enes Imsirovic
Published on 2013-07-02T20:25:03Z
Indexed on
2013/07/02
23:17 UTC
Read the original article
Hit count: 269
At first code !
Don't forget embed the JQuery !
<html>
<head>
<title>Simple jQuery and PHP Square Root example</title>
<script src="js/jquery-1.10.1.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#form').submit(function(){
var number = $('#number').val();
$.ajax({type:"post",url:"calculate.php",data:"number="
+number,success:function(msg){$('#result').hide();
$("#result").html("<h3>" + msg + "</h3>").fadeIn("slow"); } });
return false;
});
});
</script>
</head>
<body>
<form id="form" action="calculate.php" method="post">
Enter number:
<input id="number" type="text" name="number" />
<input id="submit" type="submit" value="Calculate Square Root"
name="submit"/>
</form>
<p id="result"></p>
</body>
</html>
Second code witch would be connected with first : calculate.php
<?php
if($_POST['number']==null){
echo "Please Enter a Number";
}else {
if (!is_numeric($_POST['number'])) {
echo "Please enter only numbers";
}else{
echo "Square Root of " .$_POST['number'] ." is ".sqrt($_POST['number']);
}
}
?>
Chiefly for begginers, to see the power of PHP :) xD Load this on your localhost..
PHP files and JS : https://mega.co.nz/#!Et8zWSBb!KX2PFxa2Pzw_l-wi6QU8xi_eKTlHbtQuBsT_DvXrifk
At least it look like this :
© Programmers or respective owner